package servlet;

import service.GoodsService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AdminGoodsDeleteServlet", urlPatterns = "/admin/goods_delete")
public class AdminGoodsDeleteServlet extends HttpServlet {

    GoodsService goodsService = new GoodsService();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        int id = Integer.parseInt(request.getParameter("id"));
        int pagetNum = 0;
        if (request.getParameter("pageNumber")!=null) {
            pagetNum = Integer.parseInt(request.getParameter("pageNumber"));
        }
        int type = 0;
        if (request.getParameter("type")!=null) {
            type = Integer.parseInt(request.getParameter("type"));
        }

        goodsService.delete(id);

        request.getRequestDispatcher("/admin/goods_list?pageNumber="+pagetNum+"&type="+type).forward(request,response);
    }
}
